package com.itany.corejava.day04;

import java.util.Arrays;

public class Test8 {

    public static void main(String[] args) {
        int[] arr;
        // int a[];
        /*
            1.分配空间
            2.数据初始化
            3.将空间的首地址赋值给arr
         */
        arr=new int[4];

        System.out.println("arr = " + arr);

        System.out.println("arr[2] = " + arr[2]);

        arr[1]=3;
        System.out.println("arr[1] = " + arr[1]);

        //数组的静态初始化
        int[] arr2=new int[]{1,34,6,12,87,36};
        System.out.println(arr2);
        System.out.println("arr2.length = " + arr2.length);
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }

        //错，{}只能做静态初始化不能修改值
        // arr2={1,2,3,4,5,6};
        //相当于创建了一个新的数组，丢弃了原来的数组
        arr2=new int[]{1,2,3,4,5,6};
        System.out.println(arr2);
        System.out.println(Arrays.toString(arr2));
    }


}
